package com.lh.io.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.util.Iterator;

public class Server {

    public static void main(String[] args) {

        try {
            //1.获取通道
            ServerSocketChannel channel = ServerSocketChannel.open();
            //2.切换为非阻塞
            channel.configureBlocking(false);
            //3.绑定端口
            channel.bind(new InetSocketAddress("127.0.0.1",8888));
            //4.获取选择器 selector
            Selector selector = Selector.open();
            //5.将该通道注册到选择器上
            channel.register(selector, SelectionKey.OP_ACCEPT);

            while (selector.select() > 0){
                Iterator<SelectionKey> iterator = selector.selectedKeys().iterator();

                while (iterator.hasNext()){

                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
